//
// Copyright (c) 2009 All Right Reserved
//
// Stephen Toub
// stoub@microsoft.com
// 2009-01-01
// Contains ...
using System;
using System.Globalization;
using System.IO;
using System.Text;
namespace LargoCommon.Midi {
/// A MIDI port meta event message.
[Serializable]
public sealed class MetaPort : MetaEvent {
#region Fields
/// The meta id for this event.
private const byte EventMetaId = 0x21;
/// The port for the event.
private byte port;
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The amount of time before this event.
/// The port for the event.
public MetaPort(long deltaTime, byte givenPort)
: base(deltaTime, EventMetaId) {
this.Port = givenPort;
}
#endregion
#region Properties
/// Gets or sets the port for the event.
/// General musical property.
private byte Port {
get => this.port;
set {
if (value > 0x7F) {
throw new ArgumentOutOfRangeException(nameof(value), value, "The port must be in the range from 0x0 to 0x7F.");
}
this.port = value;
}
}
#endregion
#region To String
/// Generate a string representation of the event.
/// A string representation of the event.
public override string ToString() {
var sb = new StringBuilder();
sb.Append(base.ToString());
sb.Append("\t");
sb.Append("0x");
sb.Append(this.Port.ToString("X2", CultureInfo.CurrentCulture.NumberFormat));
return sb.ToString();
}
#endregion
#region Methods
/// Write the event to the output stream.
/// The stream to which the event should be written.
public override void Write(Stream outputStream) {
if (outputStream == null) {
return;
}
//// Write out the base event information
base.Write(outputStream);
//// Event data
outputStream.WriteByte(0x01);
outputStream.WriteByte(this.port);
}
#endregion
}
}